package com.binyouwei.designpatterns.structural_type.composite;

/**
 * @author 宾有为
 * @date 2024/7/12 20:11
 * @link https://blog.csdn.net/baidu_41616022?type=blog
 * @describe：组合模式 - 把一组相似的对象当作一个单一的对象。
 **/
public class CompositeMain {
    public static void main(String[] args) {
        CompositeEmployee CEO = new CompositeEmployee("John","CEO", 30000);

        CompositeEmployee headSales = new CompositeEmployee("Robert","Head Sales", 20000);

        CompositeEmployee headMarketing = new CompositeEmployee("Michel","Head Marketing", 20000);

        CompositeEmployee clerk1 = new CompositeEmployee("Laura","Marketing", 10000);
        CompositeEmployee clerk2 = new CompositeEmployee("Bob","Marketing", 10000);

        CompositeEmployee salesExecutive1 = new CompositeEmployee("Richard","Sales", 10000);
        CompositeEmployee salesExecutive2 = new CompositeEmployee("Rob","Sales", 10000);

        CEO.add(headSales);
        CEO.add(headMarketing);

        headSales.add(salesExecutive1);
        headSales.add(salesExecutive2);

        headMarketing.add(clerk1);
        headMarketing.add(clerk2);

        //打印该组织的所有员工
        System.out.println(CEO);
        for (CompositeEmployee headEmployee : CEO.getSubordinates()) {
            System.out.println(headEmployee);
            for (CompositeEmployee employee : headEmployee.getSubordinates()) {
                System.out.println(employee);
            }
        }
    }
}
